package com.gzsxy.excel.dropDownListHandler;

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;

/**
 * @Author
 * @Description //TODO
 * @Date 2022/01/24
 * @Param $
 * @return $
 **/
public class ProductWeeklyHandler implements SheetWriteHandler {

    public String title;

    public ProductWeeklyHandler(String title) {
        this.title = title;
    }

    @Override
    public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {

    }

    @Override
    public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
        this.afterSheetCreate(writeWorkbookHolder, writeSheetHolder, title);
    }


    public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder, String title) {
        //创建workbook 工作蒲
        Workbook workbook = writeWorkbookHolder.getWorkbook();
        Sheet sheet = workbook.getSheetAt(0);

       //创建第一行
        Row row1 = sheet.createRow(0);
        row1.setHeight((short) 800);
        //获取第一个单元格(第一列)
        Cell cell1 = row1.createCell(0);
        //设置标题
        cell1.setCellValue(title);
        //创建样式
        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        //创建字体样式
        Font font = workbook.createFont();
        font.setBold(true);
        font.setFontHeight((short) 400);
        cellStyle.setFont(font);
        cell1.setCellStyle(cellStyle);
        //用于合并表格，其中四个参数含义起始行号、终止行号、起始列号、终止列号
        sheet.addMergedRegionUnsafe(new CellRangeAddress(0, 0, 0, 7));
    }
}
